﻿@using WaterRegimenMonitor.Common
@using WaterRegimenMonitor.Web.Models
@using WaterRegimenMonitor.Web.DataModel
@using WaterRegimenMonitor.Web.Domain
@using Telerik.Web.Mvc.UI
@{
    ViewBag.Title = WaterRegimenMonitor.Web.Properties.Resources.TITLE_ACCOUNT;
    Layout = "~/Views/Shared/MainLayout.cshtml";

    //获得默认密码
    string defaultPassword = System.Configuration.ConfigurationManager.AppSettings["DefaultPassword"];

    //判断是否指定了默认密码
    if (string.IsNullOrEmpty(defaultPassword))
    {
        //设置为默认值
        defaultPassword = "123456";
    }

    //用于保存角色信息
    List<string> roleModels = new List<string>();

    //判断当前用户是否为管理员
    if (Helper.CurrentPrincipal.IsInRole("SystemAdmin"))
    {
        //查询角色信息
        using (TalimuEntities entities = new TalimuEntities())
        {
            //查询所有角色信息
            foreach (Role item in entities.Role.OrderBy(item => item.TheOrder))
            {
                //转换为字符串
                roleModels.Add(string.Format("{{ boxLabel: \'{0}\', name: 'Roles', inputValue: '{1}' }}", item.RoleFullName, item.RoleID.ToString("D")));
            }
        }
    }
    else
    {
        //查询所有角色信息
        foreach (Role item in Helper.CurrentPrincipal.RoleList.OrderBy(item => item.TheOrder))
        {
            //转换为字符串
            roleModels.Add(string.Format("{{ boxLabel: \'{0}\', name: 'Roles', inputValue: '{1}' }}", item.RoleFullName, item.RoleID.ToString("D")));
        }
    }

    //用于保存单位类型信息
    List<string> organizationModels = new List<string>();

    //查询单位信息
    using (TalimuEntities entities = new TalimuEntities())
    {
        foreach (Organization item in entities.Organization.OrderBy(item => item.Organization_Code))
        {
            //转换为字符串
            organizationModels.Add(string.Format(@"{{ ID: '{0}', Name: '{1} {2}' }}", item.Organization_ID, item.Organization_Code, item.Organization_Name));
        }
    }
}
@section HeadCssLink
{
    <link href="@Url.Content("~/Content/Styles/ext-patch.css")" rel="stylesheet" type="text/css" />
}
@section HeadScriptLink
{
    <script src="@Url.Content("~/Scripts/ExtJS/locale/ext-lang-zh_CN.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/model.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/Business/Account/Index.js")" type="text/javascript"></script>
    <script type="text/javascript">
        //用于保存角色信息
        var master_roles =
        [
            @Html.Raw(System.String.Join(",", roleModels))
        ];

        //用于保存单位信息
        var master_organization =
        [
            @Html.Raw(System.String.Join(",", organizationModels))
        ];

        //用于保存默认密码
        var default_password = "@defaultPassword";

        //用于单位类型存储
        var store_master_organization = null;
    </script>
}
<h2>
    @ViewBag.Title
</h2>
<br />
<div id="data-grid" class="div-grid-box">
</div>
